import { debunce } from "@/utils";
export default function (refname) {
    return {
        mounted() {
            this.$bus.$on("setMainScroll", this.setScroll);
            this.$refs[refname].addEventListener("scroll", debunce(this.scroll, 50));
        },
        beforeDetory() {
            this.$bus.$emit('mainScroll')
            this.$refs[refname].removeEventListener("scroll", this.scroll);
            this.$bus.$off("setMainScroll", this.setScroll);
        },
        methods: {
            scroll() {
                this.$bus.$emit("mainScroll", this.$refs[refname]);
            },
            setScroll(top) {
                if (!this.$refs[refname]) return
                this.$refs[refname].scrollTop = top;
            },
        }
    }
}